package com.junzhiit.nengji.shop.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.junzhiit.nengji.shop.bo.FlowSessionCntBO;
import com.junzhiit.nengji.shop.bo.FlowStayTimeSessionBO;
import com.junzhiit.nengji.shop.bo.FlowStayTimeUvBO;
import com.junzhiit.nengji.shop.bo.FlowVisitPvBO;
import com.junzhiit.nengji.shop.bo.FlowVisitUvBO;
import com.junzhiit.nengji.shop.bo.FlowVisitUvNewBO;
import com.junzhiit.nengji.shop.dao.WechatFlowHistoryDAO;
import com.junzhiit.nengji.shop.model.WechatFlowHistory;

@Repository
public class WechatFlowHistoryDAOImpl extends AbstractBaseDAO<WechatFlowHistory> implements WechatFlowHistoryDAO {

	@Override
	public List<FlowSessionCntBO> querySessionCnt(Integer year, Integer month) {
		StringBuffer sql=new StringBuffer();
		sql.append(" select ");
		sql.append(" day(ref_date) day,sum(session_cnt) sessionCnt");
		sql.append(" from wechat_flow_history ");
		sql.append(" where ");
		sql.append(" month(ref_date)=?");
		sql.append(" and year(ref_date)=?");
		sql.append(" group by day(ref_date) ");
		
		StatementParameter param = new StatementParameter();
		param.setInt(month);
		param.setInt(year);
		
		return super.queryForList(sql.toString(),FlowSessionCntBO.class,param);
	}

	@Override
	public List<FlowVisitPvBO> queryFlowVisitPv(Integer year, Integer month) {
		StringBuffer sql=new StringBuffer();
		sql.append(" select ");
		sql.append(" day(ref_date) day,sum(visit_pv) visitPv");
		sql.append(" from wechat_flow_history ");
		sql.append(" where ");
		sql.append(" month(ref_date)=?");
		sql.append(" and year(ref_date)=?");
		sql.append(" group by day(ref_date) ");
		
		StatementParameter param = new StatementParameter();
		param.setInt(month);
		param.setInt(year);
		
		return super.queryForList(sql.toString(),FlowVisitPvBO.class,param);
	}

	@Override
	public List<FlowVisitUvBO> queryFlowVisitUv(Integer year, Integer month) {
		StringBuffer sql=new StringBuffer();
		sql.append(" select ");
		sql.append(" day(ref_date) day,sum(visit_uv) visitUv");
		sql.append(" from wechat_flow_history ");
		sql.append(" where ");
		sql.append(" month(ref_date)=?");
		sql.append(" and year(ref_date)=?");
		sql.append(" group by day(ref_date) ");		
		StatementParameter param = new StatementParameter();
		param.setInt(month);
		param.setInt(year);
		
		return super.queryForList(sql.toString(),FlowVisitUvBO.class,param);
	}

	@Override
	public List<FlowVisitUvNewBO> queryFlowVisitUvNew(Integer year, Integer month) {
		StringBuffer sql=new StringBuffer();
		sql.append(" select ");
		sql.append(" day(ref_date) day,sum(visit_uv_new) visitUvNew");
		sql.append(" from wechat_flow_history ");
		sql.append(" where ");
		sql.append(" month(ref_date)=?");
		sql.append(" and year(ref_date)=?");
		sql.append(" group by day(ref_date) ");		
		StatementParameter param = new StatementParameter();
		param.setInt(month);
		param.setInt(year);
		
		return super.queryForList(sql.toString(),FlowVisitUvNewBO.class,param);
	}

	@Override
	public List<FlowStayTimeUvBO> queryFlowStayTimeUv(Integer year, Integer month) {
		StringBuffer sql=new StringBuffer();
		sql.append(" select ");
		sql.append(" day(ref_date) day,sum(stay_time_uv) stayTimeUv");
		sql.append(" from wechat_flow_history ");
		sql.append(" where ");
		sql.append(" month(ref_date)=?");
		sql.append(" and year(ref_date)=?");
		sql.append(" group by day(ref_date) ");		
		StatementParameter param = new StatementParameter();
		param.setInt(month);
		param.setInt(year);
		
		return super.queryForList(sql.toString(),FlowStayTimeUvBO.class,param);
	}

	@Override
	public List<FlowStayTimeSessionBO> queryFlowStayTimeSession(Integer year, Integer month) {
		StringBuffer sql=new StringBuffer();
		sql.append(" select ");
		sql.append(" day(ref_date) day,sum(stay_time_session) stayTimeSession");
		sql.append(" from wechat_flow_history ");
		sql.append(" where ");
		sql.append(" month(ref_date)=?");
		sql.append(" and year(ref_date)=?");
		sql.append(" group by day(ref_date) ");
		
		StatementParameter param = new StatementParameter();
		param.setInt(month);
		param.setInt(year);
		
		return super.queryForList(sql.toString(),FlowStayTimeSessionBO.class,param);
	}

}
